package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TestAddWeekDays {

    private static final Logger log = LoggerFactory.getLogger(TestAddWeekDays.class);

    public static void main(String[] args) {
        String dateString = addWeekDays("2023-04-04",9);
        System.out.println(dateString);
    }



    public static String addWeekDays(String dateString,int days){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(dateString);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            for(int i = 0;i < days ; i ++){
                calendar.add(Calendar.DATE,1);
                System.out.println(calendar.get(Calendar.DAY_OF_WEEK)+":"+calendar.getTime());
                if(calendar.get(Calendar.DAY_OF_WEEK) == 7 || calendar.get(Calendar.DAY_OF_WEEK) == 0){
                    //calendar.add(Calendar.DATE,1);
                }
            }
            return calendar.getTime().toString();
        }catch (Exception e){
            log.error("日期格式化失败！",e);
        }

        return null;
    }
}
